home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS05.ADF / IFF / ilbm2raw.c < prev    next >
C/C++ Source or Header  |  1986-04-20  |  5KB  |  141 lines

  1.  
  2. /*--------------------------------------------------------------*/
  3. /* ilbm2raw.c                                */   
  4. /*            2/4/86                         */
  5. /* Reads in ILBM, outputs raw format, which is              */
  6. /* just the planes of bitmap data followed by the color map */
  7. /*                                                              */
  8. /* By Jerry Morrison and Steve Shaw, Electronic Arts.           */
  9. /* This software is in the public domain.                       */
  10. /*                                                              */
  11. /* This version for the Commodore-Amiga computer.               */
  12. /*                                                              */
  13. /*   Callable from CLI only                       */
  14. /*--------------------------------------------------------------*/
  15.  
  16. #include "iff/intuall.h"
  17. #include "libraries/dos.h"
  18. #include "libraries/dosextens.h"
  19. #include "iff/ilbm.h"
  20. #include "iff/readpict.h"
  21. #include "iff/remalloc.h"
  22.  
  23. #undef NULL
  24. #include "lattice/stdio.h"
  25. /*----------------------------------------------------------------------*/
  26. /*   Iff error messages                           */
  27. /*----------------------------------------------------------------------*/
  28.  
  29. char MsgOkay[] = { "----- (IFF_OKAY) A good IFF file." };
  30. char MsgEndMark[] = {"----- (END_MARK) How did you get this message??" };
  31. char MsgDone[] = { "----- (IFF_DONE) How did you get this message??" };
  32. char MsgDos[] = { "----- (DOS_ERROR) The DOS gave back an error." };
  33. char MsgNot[] = { "----- (NOT_IFF) not an IFF file." };
  34. char MsgNoFile[] = { "----- (NO_FILE) no such file found." };
  35. char MsgClientError[] = {"----- (CLIENT_ERROR) IFF Checker bug."};
  36. char MsgForm[] = { "----- (BAD_FORM) How did you get this message??" };
  37. char MsgShort[] = { "----- (SHORT_CHUNK) How did you get this message??" };
  38. char MsgBad[] = { "----- (BAD_IFF) a mangled IFF file." };
  39.  
  40. /* MUST GET THESE IN RIGHT ORDER!!*/
  41. char *IFFPMessages[-LAST_ERROR+1] = {
  42.     /*IFF_OKAY*/  MsgOkay,
  43.     /*END_MARK*/  MsgEndMark,
  44.     /*IFF_DONE*/  MsgDone,
  45.     /*DOS_ERROR*/ MsgDos,
  46.     /*NOT_IFF*/   MsgNot,
  47.     /*NO_FILE*/   MsgNoFile,
  48.     /*CLIENT_ERROR*/ MsgClientError,
  49.     /*BAD_FORM*/  MsgForm,
  50.     /*SHORT_CHUNK*/  MsgShort,
  51.     /*BAD_IFF*/   MsgBad
  52.     };
  53.  
  54. LONG GfxBase;
  55.  
  56. /*--------------------------------------------------------------*/
  57.  
  58. SaveBitMap(name,bm,cols)
  59.     UBYTE *name;    
  60.     struct BitMap *bm;
  61.     SHORT *cols;
  62.     {
  63.     SHORT i;
  64.     LONG nb,plsize;
  65.     LONG file = Open( name, MODE_NEWFILE);
  66.     if( file == 0 )  {
  67.      printf(" couldn't open %s \n",name);
  68.      return (-1);   /* couldnt open a load-file */     
  69.      }
  70.     plsize = bm->BytesPerRow*bm->Rows;
  71.     for (i=0; i<bm->Depth; i++) {
  72.      nb =  Write(file, bm->Planes[i], plsize);
  73.      if (nb<plsize) break;
  74.      }
  75.     Write(file, cols, (1<<bm->Depth)*2);     /* save color map */
  76.     Close(file);
  77.     return(0);
  78.     }
  79.  
  80. struct BitMap bitmap = {0};
  81.  
  82. char depthString[] = "0";     /* Replaced with desired digit below.*/
  83.  
  84. ILBMFrame ilbmFrame;     /* Top level "client frame".*/
  85.  
  86. /** main() ******************************************************************/
  87.  
  88. UBYTE defSwitch[] = "b";
  89.  
  90. void main(argc, argv)  int argc;  char **argv;  {
  91.     LONG iffp, file;
  92.     UBYTE fname[40];
  93.     GfxBase = (LONG)OpenLibrary("graphics.library",0);
  94.     if (GfxBase==NULL) exit(0);
  95.     
  96.     if (argc) {
  97.      /* Invoked via CLI.  Make a lock for current directory. */
  98.      if (argc < 2) {
  99.          printf("Usage from CLI: 'ilbm2raw filename '\n");
  100.          }
  101.      else {
  102.          
  103.          file = Open(argv[1], MODE_OLDFILE);
  104.          
  105.          if (file) {
  106.           iffp = ReadPicture(file, &bitmap, &ilbmFrame, ChipAlloc);
  107.           Close(file);
  108.           if (iffp != IFF_DONE) {
  109.               printf(" Couldn't read file %s \n", argv[1]);
  110.               printf("%s\n",IFFPMessages[-iffp]);
  111.               }
  112.           else {
  113.               
  114.               strcpy(fname,argv[1]);
  115.  
  116.               if (ilbmFrame.bmHdr.pageWidth > 320) {
  117.                if (ilbmFrame.bmHdr.pageHeight > 200)
  118.                     strcat(fname, ".hi");
  119.                else strcat(fname, ".me");
  120.                }
  121.               else     strcat(fname, ".lo");
  122.  
  123.               depthString[0] = '0' + bitmap.Depth;
  124.               strcat(fname, depthString);
  125.  
  126.               printf(" Creating file %s \n", fname);
  127.               SaveBitMap(fname, &bitmap, ilbmFrame.colorMap);
  128.               }
  129.           }
  130.          else printf(" Couldn't open file: %s. \n", argv[1]);
  131.  
  132.          if (bitmap.Planes[0])  RemFree(bitmap.Planes[0]);
  133.  
  134.          printf("\n");
  135.          }
  136.      }
  137.     CloseLibrary(GfxBase);
  138.     exit(0);
  139.     }
  140.  
  141.